<?php
/**
 * Table Definition for Amway_product
 */

class Amway_product extends Memcached_DataObject
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    public $__table = 'am_product';                      // table name
    public $id;                              // int(10)  primary_key not_null
    public $product_code;                        // varchar(45)  unique_key
    public $product_name;                        // varchar(200)
    public $pro_line_id;                        // int(10) 
    public $description;                     // varchar(200)
    public $effects;                     // varchar(200)
    public $current_price;                     // decimal(10,2)
    public $is_active;                        // smallint
    public $created_at;                   // timestamp(255)
    public $updated_at;                   // timestamp(255)
     public $original;                        // tinyint(1)
    public $width;                           // int(4)  primary_key null
    public $height;                          // int(4)  primary_key null
    public $mediatype;                       // varchar(32)   null
    public $filename;                        // varchar(255)
    public $url;                             // varchar(255)  unique_key

    /* Static get */
    function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Amway_product',$k,$v); }

    function &pkeyGet($kv)
    {
        return Memcached_DataObject::pkeyGet('Amway_product', $kv);
    }    
// where should the avatar go for this user?

    static function filename($id, $extension, $size=null, $extra=null)
    {
        if ($size) {
            return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
        } else {
            return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension;
        }
    }

    static function path($filename)
    {
        $dir = common_config('avatar', 'dir');

        if ($dir[strlen($dir)-1] != '/') {
            $dir .= '/';
        }

        return $dir . $filename;
    }

    static function url($filename)
    {
        $path = common_config('avatar', 'path');

        if ($path[strlen($path)-1] != '/') {
            $path .= '/';
        }

        if ($path[0] != '/') {
            $path = '/'.$path;
        }

        $server = common_config('avatar', 'server');

        if (empty($server)) {
            $server = common_config('site', 'server');
        }

        // XXX: protocol

        return 'http://'.$server.$path.$filename;
    }

    function displayUrl()
    {
        $server = common_config('avatar', 'server');
        if ($server) {
            return Amway_product::url($this->filename);
        } else {
            return $this->url;
        }
    }

    static function defaultImage($size)
    {
        static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
                                  AVATAR_STREAM_SIZE => 'stream',
                                  AVATAR_MINI_SIZE => 'mini');
        return theme_path('default-avatar-'.$sizenames[$size].'.png');
    }
}
